package com.example.origin.spider.webmagic;

import com.example.origin.spider.properties.ProcessorProperties;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.SerializationUtils;
import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.SpiderListener;

@Slf4j
@AllArgsConstructor
public class DingDingSpiderListener implements SpiderListener {


    private ProcessorProperties properties;



    @Override
    public void onSuccess(Request request) {
        Object cycleTriedTimesObject = request.getExtra(Request.CYCLE_TRIED_TIMES);
        if (cycleTriedTimesObject != null) {
            int cycleTriedTimes = (Integer) cycleTriedTimesObject;
            if (properties.getCycleRetryTimes()>cycleTriedTimes) {
                log.warn("error>> {}-{}","dingding alert",cycleTriedTimes+1);
            }
        }

    }

    @Override
    public void onError(Request request, Exception e) {
        log.warn("error>> {}","dingding alert");
    }
}
